//
//  ZQTabBaController.m
//  BuDeJie
//
//  Created by 仲琦 on 16/3/31.
//  Copyright © 2016年 仲琦. All rights reserved.
//

#import "ZQTabBaController.h"

#import "ZQEssenceViewController.h"
#import "ZQNewViewController.h"
#import "ZQPublishViewController.h"
#import "ZQFriendThrendViewController.h"
#import "ZQMeViewController.h"
#import "ZQTabBar.h"
#import "UIImage+ZQRender.h"
#import "ZQNavigationController.h"
@interface ZQTabBaController ()

@end

@implementation ZQTabBaController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupAllChildViewController];
    
    [self setTabBarButton];
}

    //设置TabBar的字体颜色
+ (void)load
{

    //获取全局的TabBarItem   appearance
    UITabBarItem *item = [UITabBarItem appearance];
    
    //创建字典描述文本
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor blackColor];
    
    //创建字典描述文本
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    
    //设置TabBar的字体颜色
    [item setTitleTextAttributes:dict forState:UIControlStateSelected];
    //设置TabBar的字体大小
    [item setTitleTextAttributes:dictM forState:UIControlStateNormal];
}

#pragma mark - 自定义TabBar
- (void)setTabBarButton
{
    ZQTabBar *tabBar = [[ZQTabBar alloc]init];
    
    [self setValue:tabBar forKey:@"tabBar"];
    
    
}

#pragma mark - 添加所有子控制器
- (void)setupAllChildViewController
{
    ZQEssenceViewController *vc1 = [[ZQEssenceViewController alloc]init];
    [self addChildVC:vc1 Title:@"精华" image:[UIImage imageNamed:@"tabBar_essence_icon"] selectImage:[UIImage imageNamed:@"tabBar_essence_click_icon"]];
    
    ZQNewViewController *vc2 = [[ZQNewViewController alloc]init];
    [self addChildVC:vc2 Title:@"新帖" image:[UIImage imageNamed:@"tabBar_new_icon"] selectImage:[UIImage imageNamed:@"tabBar_new_click_icon"]];
    
//    ZQPublishViewController *vc3 = [[ZQPublishViewController alloc]init];
//    [self addChildVC:vc3 Title:nil image:[UIImage imageNamed:@"tabBar_publish_icon"] selectImage:[UIImage imageNamed:@"tabBar_publish_click_icon"]];

    
    ZQFriendThrendViewController *vc4 = [[ZQFriendThrendViewController alloc]init];
    [self addChildVC:vc4 Title:@"关注" image:[UIImage imageNamed:@"tabBar_friendTrends_icon"] selectImage:[UIImage imageNamed:@"tabBar_friendTrends_click_icon"]];
    
    
    

    
    //加载stroyBoard控制器
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ZQMeViewController" bundle:nil];
    ZQMeViewController *vc5 = [sb instantiateInitialViewController];

    [self addChildVC:vc5 Title:@"我的" image:[UIImage imageNamed:@"tabBar_me_icon"] selectImage:[UIImage imageNamed:@"tabBar_me_click_icon"]];
    



    
    
}

#pragma mark - 抽取添加子控制器方法
- (void)addChildVC:(UIViewController *)vc Title:(NSString *)title image:(UIImage *)image selectImage:(UIImage *)selectImage
{
//        if (![vc isKindOfClass:[ZQPublishViewController class]]) {

//        vc.tabBarItem.image = image;
//        vc.tabBarItem.selectedImage = selectImage;
//        [self addChildViewController:vc];
//    }else{
        ZQNavigationController *nav = [[ZQNavigationController alloc]initWithRootViewController:vc];
        
        nav.title = title;
        nav.tabBarItem.image = image;
        nav.tabBarItem.selectedImage = selectImage;
        [self addChildViewController:nav];
//    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
